home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 051a / tbav603.zip / TBGENSIG.DOC < prev    next >
Text File  |  1993-06-15  |  21KB  |  661 lines

  1.  
  2.  
  3.  Thunderbyte signature compiler. (C) Copyright 1993 Thunderbyte B.V.
  4.  
  5.  
  6.                                Table of Contents
  7.  
  8.  
  9.     1. INTRODUCTION...................................... 2
  10.         1.1. Purpose of TbGenSig......................... 2
  11.         1.2. General information......................... 2
  12.  
  13.     2. DEFINING SIGNATURES............................... 2
  14.         2.1. Format of the UserSig.Dat file.............. 2
  15.         2.2. Adding a published signature................ 3
  16.         2.3. Defining a signature with TbScan............ 3
  17.  
  18.     3. ADVANCED FEATURES................................. 5
  19.         3.1. Keywords.................................... 5
  20.             3.1.1. Item keywords......................... 5
  21.             3.1.2. Message keywords...................... 6
  22.             3.1.3. Position keywords..................... 6
  23.         3.2. Wildcards................................... 8
  24.             3.2.1. Position wildcards.................... 8
  25.                 3.2.1.1. Skip............................ 8
  26.                 3.2.1.2. Variable........................ 8
  27.             3.2.2. Opcode wildcards...................... 8
  28.                 3.2.2.1. Low opcode...................... 8
  29.                 3.2.2.2. High opcode..................... 8
  30.         3.3. Example..................................... 9
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.                                      Page i
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.                                      Page 1
  122.  
  123.  Thunderbyte signature compiler. (C) Copyright 1993 Thunderbyte B.V.
  124.  
  125.  
  126. 1.  INTRODUCTION
  127.  
  128.  
  129.   1.1.  Purpose of TbGenSig
  130.  
  131.     TbGenSig is a signature file compiler. Since TBAV is distributed
  132.     with an up to date, ready-to-use signature file, you don't really
  133.     need the signature file compiler.
  134.  
  135.     However, you need the signature file compiler if you want to define
  136.     your own virus signatures. You can used either published signatures
  137.     or define your own ones if you are familiar with the structure of
  138.     software.
  139.  
  140.     In both cases, you only need to do this in emergency situations,
  141.     like the unfortunate event that your machine or even company is
  142.     attacked by an yet unknown and thus not recognized virus. It is
  143.     recommended to send a few samples of the virus to some virus
  144.     experts anyway, in order to make scanners to recognize the virus in
  145.     the next versions of the scanners.
  146.  
  147.     It isn't possible to explain the whole subject of virus hunting in
  148.     one manual, so this document assumes that you have enough
  149.     expenrience and knowledge to make your own signatures.
  150.  
  151.  
  152.   1.2.  General information
  153.  
  154.     TbGenSig searches for a file name UserSig.Dat in the current
  155.     directory. This file should contain the signatures you want to add
  156.     to the TBAV signature file TbScan.Sig. TbGenSig checks the contents
  157.     of the UserSig.Dat file and applies it to the TbScan.Sig file.
  158.  
  159.     If you want to delete or modify your signatures, just edit or
  160.     delete the UserSig.Dat file and run TbGenSig again.
  161.  
  162.     TbGenSig will list all signatures in the TbScan.Sig file on the
  163.     screen when running.
  164.  
  165.  
  166. 2.  DEFINING SIGNATURES
  167.  
  168.  
  169.   2.1.  Format of the UserSig.Dat file
  170.  
  171.     You can create and edit the UserSig.Dat file with every DOS text
  172.     editor able to output unformatted text.
  173.  
  174.     All lines starting with ';' are comment lines. TbGenSig ignores
  175.     these lines.
  176.  
  177.     Lines starting with '%' will be displayed in the upper TbGenSig
  178.  
  179.  
  180.  
  181.                                      Page 2
  182.  
  183.  Thunderbyte signature compiler. (C) Copyright 1993 Thunderbyte B.V.
  184.  
  185.  
  186.     window.
  187.  
  188.     In the first line the name of a virus is expected. The second line
  189.     contains one or more keywords. The third line contains the
  190.     signature itself. This combination of three lines is named a
  191.     signature record.
  192.  
  193.     An signature record should look like this:
  194.  
  195.         Test virus
  196.         exe com inf
  197.         abcd21436587abcd
  198.  
  199.     It is allowed to use spaces in the signature for your own
  200.     convenience. TbGenSig will ignore those spaces.
  201.  
  202.  
  203.   2.2.  Adding a published signature
  204.  
  205.     If you want to add a signature that has been published, do the
  206.     following.
  207.  
  208.     -   Edit or create the UserSig.Dat file. Convert the published
  209.         signature to an acceptable format for TbGenSig.
  210.  
  211.     -   Use keywords COM EXE BOOT INF
  212.  
  213.         You would get:
  214.  
  215.                 New virus
  216.                 exe com boot inf
  217.                 1234abcd5678efab
  218.  
  219.     -   Execute TbGenSig.
  220.  
  221.  
  222.   2.3.  Defining a signature with TbScan
  223.  
  224.     This chapter is intended for advanced users who own a TBAV.KEY
  225.     file or a Thunderbyte add-on card.
  226.  
  227.     Although the TbScan.Sig file is updated frequently, new viruses are
  228.     created each day, outpacing the regular upgrading service of this
  229.     data file. It is therefore possible that one day your system gets
  230.     infected by a recently created virus that has not yet been listed
  231.     in the signature file.  TbScan will not always detect the virus
  232.     in such cases, not even with the heuristic analysis.  If you are
  233.     convinced that your system must have been infected without TbScan
  234.     confirming this, this chapter will supply you with a valuable tool
  235.     to detect undocumented viruses with. We offer you step-by-step
  236.     assistance here in creating an emergency signature that can be
  237.     (temporarily) added to your copy of TbScan.Sig
  238.  
  239.  
  240.  
  241.                                      Page 3
  242.  
  243.  Thunderbyte signature compiler. (C) Copyright 1993 Thunderbyte B.V.
  244.  
  245.  
  246.     -   Collect some infected files and copy them into a temporary
  247.         directory.
  248.  
  249.     -   Boot from a clean write-protected diskette. Do NOT execute ANY
  250.         program from the infected system, even though you expect this
  251.         program to be clean.
  252.  
  253.     -   Execute TbScan from your write-protected TbScan diskette with
  254.         the 'extract' option set. Make sure that the temporary directory
  255.         where you put the infected files will be TbScan's target
  256.         directory. With its 'extract' option set, TbScan will NOT scan
  257.         the files but, instead, display the first instructions that are
  258.         found at the entry-point of the infected programs.  Please note
  259.         that we highly recommend you to simultaneously set the
  260.         'session' option of TbScan to generate a log file.
  261.  
  262.     -   Compare the 'signatures' extracted by TbScan. You should see
  263.         something like this:
  264.  
  265.                 NOVIRUS1.COM    2E67BCDEAB129090909090ABCD123490CD
  266.                 NOVIRUS2.COM    N/A
  267.                 VIRUS1.COM      1234ABCD5678EFAB909090ABCD123478FF
  268.                 VIRUS2.COM      1234ABCD5678EFAB901234ABCD123478FF
  269.                 VIRUS3.COM      1234ABCD5678EFAB9A5678ABCD123478FF
  270.  
  271.         If the 'signatures' are completely different, the files are
  272.         probably not infected, else they have been infected by a
  273.         polymorphic virus that requires an AVR module to detect it.
  274.  
  275.     -   There might be some differences in the 'signatures'. You can
  276.         use the question mark wildcard ('?') in this case.
  277.  
  278.         A signature to detect the 'virus' in the example above could be:
  279.  
  280.                 1234ABCD5678EFAB ?3 ABCD123478FF
  281.  
  282.         The '?3' means that there are three bytes on that position that
  283.         should be skipped.
  284.  
  285.     -   Add the signature to the data file UserSig.Dat file. Give the
  286.         virus a name in the first line of its entry. Specify the
  287.         following keywords: COM, EXE, INF, ATE keywords in the second
  288.         line.  Enter the signature on the third.
  289.  
  290.         You would get:
  291.  
  292.                 New virus
  293.                 exe com ate inf
  294.                 1234abcd5678efab?3abcd123478ff
  295.  
  296.     -   Execute TbGenSig. Make sure the resulting TbScan.Sig file is in
  297.         the TbScan directory.
  298.  
  299.  
  300.  
  301.                                      Page 4
  302.  
  303.  Thunderbyte signature compiler. (C) Copyright 1993 Thunderbyte B.V.
  304.  
  305.  
  306.     -   Run TbScan again in the directory containing the infected
  307.         files. TbScan should now detect the virus.
  308.  
  309.     -   Send a couple of infected files to a recommended virus expert,
  310.         preferably to us.
  311.  
  312.     Congratulations! You have defined a signature all by yourself! Now
  313.     you can scan all your machines in search of the new virus.
  314.     However, keep in mind that this method of extracting a  signature
  315.     is a 'quick-and-dirty' solution to viral problems. The extracted
  316.     signature might not detect the presence of the virus in all cases. A
  317.     signature that is guaranteed to detect all instances of the virus
  318.     can be made only after complete disassembly of the new virus.  For
  319.     these reasons you should NOT distribute your home-made 'signature'
  320.     to others.  The signature eventually assembled by experienced
  321.     anti-virus researchers will be completely different in most cases!
  322.  
  323.  
  324. 3.  ADVANCED FEATURES
  325.  
  326.  
  327.   3.1.  Keywords
  328.  
  329.     Keywords are used for several purposes. They are classified in
  330.     categories.
  331.  
  332.     Keywords may be separated by spaces, commas or tabs. The maximum
  333.     line length is 80 bytes.
  334.  
  335.     At least one of the following flags should be specified:
  336.     BOOT, COM, EXE, HIGH, LOW, SYS or WIN.
  337.  
  338.  
  339.   3.1.1.  Item keywords
  340.  
  341.     BOOT    Signature can be found in bootsector/partition code.
  342.  
  343.     COM     Signature can be found in COM programs.
  344.             This flag causes the scanner to search for this signature
  345.             in executable files that do not have an EXE header or
  346.             device header.
  347.             Note:
  348.             The file contents determines the file type, not the
  349.             filename extension!
  350.  
  351.     EXE     Signature can be found in EXE programs.
  352.             This flag causes the scanner to search for this signature
  353.             in the load module of EXE type files. EXE files are files
  354.             that have an EXE header.
  355.             Note:
  356.             The file contents determines the file type, not the
  357.             filename extension!
  358.  
  359.  
  360.  
  361.                                      Page 5
  362.  
  363.  Thunderbyte signature compiler. (C) Copyright 1993 Thunderbyte B.V.
  364.  
  365.  
  366.     HIGH    Signature can be found in HIGH memory (above program).
  367.             This flag causes the scanner to search for this signature
  368.             in memory above the memory allocated by the scanner.
  369.             This keyword is intended for resident viruses that allocate
  370.             memory at system boot, or viruses that decrease the size of
  371.             the last MCB (Memory Control Block).
  372.             Note:
  373.             The flag HIGH does not mean that the signature should be
  374.             searched in Upper memory.
  375.  
  376.     LOW     Signature can be found in LOW memory.
  377.             This flag causes the scanner to search for this signature
  378.             in memory below the PSP (Program Segment Prefix) of the
  379.             scanner and in the UMB (Upper Memory Blocks).
  380.             This keyword is intended for viruses that remain resident
  381.             in memory, using the normal DOS TSR (Terminate and Stay
  382.             Resident) function calls.
  383.  
  384.     SYS     Signature can be found in SYS programs.
  385.  
  386.     WIN     Signature can be found in Windows programs.
  387.  
  388.  
  389.   3.1.2.  Message keywords
  390.  
  391.     DAM     Message prefix: 'damaged by'.
  392.     DROP    Message prefix: 'dropper of'.
  393.     FND     Message prefix: 'found the'.
  394.     INF     Message prefix: 'infected by' Message suffix: 'virus'
  395.     JOKE    Message prefix: 'joke named'.
  396.     OVW     Message prefix: 'overwritten by'.
  397.     PROB    Message pre-prefix: 'probably'.
  398.     TROJ    Message prefix: 'trojanized by'.
  399.  
  400.  
  401.   3.1.3.  Position keywords
  402.  
  403.     UATE    Signature should be found at unresolved entry point.
  404.  
  405.         Purpose:
  406.             The signature starts directly at the unresolved entry-point
  407.             of the virus-code. With some polymorphic viruses, it may be
  408.             possible to create a signature from the degarbling routine,
  409.             but it may be too short or it may give false positives with
  410.             a global search. An initial branch instruction may make
  411.             part of the signature.
  412.  
  413.             COM type files:     top of file (IP 0100h).
  414.             EXE type files:     CS:IP as defined in the EXE-header.
  415.             WIN type files:     Non-DOS CS:IP of the new EXE-header.
  416.  
  417.         Remarks:
  418.  
  419.  
  420.  
  421.                                      Page 6
  422.  
  423.  Thunderbyte signature compiler. (C) Copyright 1993 Thunderbyte B.V.
  424.  
  425.  
  426.             The keyword UATE is not allowed for BOOT, SYS, LOW, HMA or
  427.             HIGH type signatures.
  428.  
  429.     ATE     Signature should be found AT ENTRY point.
  430.  
  431.         Purpose:
  432.             The signature starts directly at the entry-point of the
  433.             virus-code. With some polymorphic viruses, it may be
  434.             possible to create a signature from the degarbling routine,
  435.             but it may be too short or it may give false positives with
  436.             a global search.
  437.  
  438.             Therefor the keyword ATE is used to make sure that the
  439.             scanners do not scan the entire file for the signature, but
  440.             only looks at the entry-point for the signature.
  441.  
  442.             The entry-point of a virus is defined by the first byte
  443.             that is not equal to either a JUMP SHORT, JUMP LONG or a
  444.             CALL NEAR.
  445.  
  446.                 Unresolved entry point: 1    JUMP LONG 3
  447.                                         2    ...
  448.                                         3    JUMP SHORT 5
  449.                                         4    ...
  450.                                         5    CALL FAR 7
  451.                                         6    ...
  452.                                         7    CALL NEAR 9
  453.                                         8    ...
  454.                 Resolved entry point:   9    POP <reg>
  455.  
  456.             The entry-point of the above fragment is Line 9 as this is
  457.             the first code to be executed which is not a JUMP SHORT,
  458.             JUMP LONG or CALL NEAR or CALL FAR.
  459.  
  460.         Remarks:
  461.             1) The entry-point can be determined by a code analyzer to
  462.             cope with tricks like coding a NOP or DEC just before the
  463.             branch instruction. Therefore the results of the scanner
  464.             should be tested carefully. In case of trouble use the
  465.             TbScan 'extract' option to find out what TbScan considers
  466.             to be the entry point of the program.
  467.  
  468.             2) The flag UATE is not allowed for BOOT, SYS, LOW, HMA or
  469.             HIGH type signatures.
  470.  
  471.     XHD     Signature can be found at offset 2 of EXE file.
  472.  
  473.         Purpose:
  474.             This position keyword is rarely used. It should only be
  475.             used to detect the also very rare high-level language
  476.             viruses; viruses written in a language like C or Basic.
  477.             These viruses normally contain standard setup routines and
  478.  
  479.  
  480.  
  481.                                      Page 7
  482.  
  483.  Thunderbyte signature compiler. (C) Copyright 1993 Thunderbyte B.V.
  484.  
  485.  
  486.             library routines which are not suitable to define a
  487.             signature. The XHD keyword can be used as a last resort to
  488.             detect such viruses.
  489.  
  490.         Remarks:
  491.             This flag may only be used for EXE or WIN type signatures.
  492.  
  493.  
  494.   3.2.  Wildcards
  495.  
  496.     In a virus signature, wildcards characters may be used to recognize
  497.     so called polymorphic (self- modifying/mutating) virus code. Below
  498.     is a description of the wildcard notation. All numbers are in
  499.     hexadecimal.
  500.  
  501.  
  502.   3.2.1.  Position wildcards.
  503.  
  504.     Position wildcards affect the position where the parts of the
  505.     signature will be matched.
  506.  
  507.   3.2.1.1.  Skip
  508.  
  509.         ?n   =  Skip n amount of bytes and continue.
  510.         ?@nn =  Skip nn amount of bytes and continue.
  511.                 nn should not exceed 7F.
  512.  
  513.   3.2.1.2.  Variable
  514.  
  515.         *n   =  Skip up to n bytes.
  516.         *@nn =  Skip up to nn bytes and continue.
  517.                 nn should not exceed 1F.
  518.  
  519.  
  520.   3.2.2.  Opcode wildcards.
  521.  
  522.     The 'opcode' wildcards are shaped to detect instruction ranges:
  523.  
  524.   3.2.2.1.  Low opcode
  525.  
  526.         nL   =  One of the values in the range n0-n7.
  527.  
  528.   3.2.2.2.  High opcode
  529.  
  530.         nH   =  One of the values in the range n8-nF.
  531.  
  532.     Intended use of the opcode wildcards:
  533.  
  534.     Suppose a polymorphic virus puts a value in a word register (using
  535.     a MOV WREG,VALUE instruction), and increments a register (using an
  536.     INC WREG instruction, and pops a word register from the stack
  537.     (using a POP instruction).  The registers are variable and
  538.  
  539.  
  540.  
  541.                                      Page 8
  542.  
  543.  Thunderbyte signature compiler. (C) Copyright 1993 Thunderbyte B.V.
  544.  
  545.  
  546.     the value too.  You could code it like this:
  547.  
  548.         bh4l5h
  549.  
  550.     B8-BF are the opcodes for 'MOV WREG,VALUE', 40-47 are the
  551.     opcodes for 'INC WREG', and 58-5F are the opcodes for 'POP REG'.
  552.  
  553.  
  554.   3.3.  Example
  555.  
  556.     To show the power of the use of the appropriate keywords and
  557.     wildcards here is the signature of the Haifa.Mozkin virus.
  558.  
  559.     This virus is highly polymorphic and encrypted. It uses a small
  560.     variable decryptor to decrypt the virus.
  561.  
  562.     There are two problems here: most bytes are encrypted or variable
  563.     and not suitable to make part of a signature, and the remainder is
  564.     short and would cause dozens of false alarms.
  565.  
  566.     However, using the appropriate keywords and wildcards, it is
  567.     possible to define a reliable signature. The signature below is
  568.     used by TbScan to detect the Haifa.Mozkin virus.
  569.  
  570.         Haifa.Mozkin
  571.         com exe ate inf
  572.         bh?2bh?109?2*22e80?24l4h75fl
  573.  
  574.     Let's analyze it.
  575.  
  576.     The first line describes the name of the virus.
  577.  
  578.     The second line tells the scanner to search for this signature in
  579.     COM and EXE type files. It also tells the scanner that it should
  580.     report the file as infected if the signature can be matched. The
  581.     keyword ATE instructs the scanner to match this signature only at
  582.     the resolved entry-point of the file. The virus starts of course
  583.     with decrypting itself, so it is guaranteed that the scanner will
  584.     finally reach this location. The ATE instruction limits the scope
  585.     of this signature to just one position in a file, so this will
  586.     reduce the chances of false alarms significantly.
  587.  
  588.     The third line is the signature definition. Let's reverse engineer
  589.     it:
  590.  
  591.     bh?2        This means: a byte in the range B8-BF followed by two
  592.                 variable bytes. B8-BF is a 'MOV WREG,VALUE'
  593.                 instruction. From the register we only know it is a
  594.                 word register, and the value is unknown.
  595.  
  596.     bh?109      This means: another 'MOV WREG,VALUE' instruction. The
  597.                 register is a word register, and from the value we know
  598.  
  599.  
  600.  
  601.                                      Page 9
  602.  
  603.  Thunderbyte signature compiler. (C) Copyright 1993 Thunderbyte B.V.
  604.  
  605.  
  606.                 that it is in the range 0900 to 09FF.
  607.  
  608.     ?2*2        This means: skip two to four bytes. This stuff is
  609.                 inserted by the virus to make it harder to define a
  610.                 signature.
  611.  
  612.     2e80?2      This means: the virus performs an arithmethic byte
  613.                 sized operation with an immediate value (decrypts one
  614.                 byte) with a CS: segment override. The exact operation,
  615.                 the memory location and the value are unknown.
  616.  
  617.     4l          This means: a byte in the range 40-47. This is a 'INC
  618.                 WREG' instruction. The viruses increments the counter
  619.                 to the next byte to be decrypted.
  620.  
  621.     4h          This means: a byte in the range 48-4F. This is a 'DEC
  622.                 WREG' instruction. The viruses decrements the iteration
  623.                 count.
  624.  
  625.     75fl        Opcode 75 is a JNZ instruction. If the decremented
  626.                 register did not reach zero, the virus jumps back and
  627.                 repeats the operation. How much does it jump? That
  628.                 tells the 'fl' part: somewhere between -70h (F0h) to
  629.                 -77h (F7h) bytes.
  630.  
  631.  
  632.     Although the signature language of TbGenSig is very powerful, there
  633.     are viruses which are so highly polymorphic that they require even
  634.     more sophisticated wildcards, keywords or even special detection
  635.     algorithms. The explanations however of these wildcards, keywords
  636.     or algorithmic detection definitions are so complicated that they
  637.     are not suitable for this manual.
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.                                     Page 10